/**
 * 
 */
package design_pattern.interpreter;

/**
 * @author linzq
 * 
 */
public class Not implements Expression {

  private Expression exp;

  public Not(Expression exp) {
    this.exp = exp;
  }

  @Override
  public boolean interpret(Context ctx) {
    return exp.interpret(ctx);
  }

  @Override
  public int hashCode() {
    return this.toString().hashCode();
  }

  /**
   * 检验两个表达式在结构上是否相同
   */
  @Override
  public boolean equals(Object obj) {
    if (obj != null && obj instanceof Not) {
      return this.exp.equals(((Not) obj).exp);
    }
    return false;
  }

  @Override
  public String toString() {
    return "(Not " + exp.toString() + ")";
  }

}
